package com.hermes.biz.timerTask;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import org.directwebremoting.ScriptSession;
import org.directwebremoting.proxy.dwr.Util;
import com.hermes.biz.sessionCenter.SsionManager;
import com.hermes.biz.common.constants.CommonSplitCodeConstants;
import com.hermes.biz.sessionCenter.Qsession;

public class MsgPushTask {
	Set<String> msgSendUserIdSet = new HashSet<String>();
	SsionManager ssionManager;



	private final Timer msgPushTimer = new Timer();	
	
	public void start(){
		msgPushTimer.schedule(new TimerTask(){
			public void run(){
				pushMsg();
			}
		}, CommonSplitCodeConstants.timer_time,CommonSplitCodeConstants.timer_time);
	}
	
	private void pushMsg(){

		msgSendUserIdSet.add("7");
		
		int newMsgCount = getNewMsgCount(0);
		SsionManager.getAllSession();
		Set<String> key = SsionManager.getAllSession().keySet();
		
		for(String tempUserId : msgSendUserIdSet){
			for(Iterator it = key.iterator();it.hasNext();){
				String skey = (String) it.next();
				if(skey.equals(tempUserId)){
					Qsession q =  ssionManager.getAllSession().get(tempUserId);
					ScriptSession sss = q.getSsionEntry();
					Util util = new Util(sss);
					util.setValue("msg", "mmmmmm");
					
					
//					Qsession qValue = (Qsession) SsionManager.getAllSession().get(skey);
//					ScriptSession ss = qValue.getSsionEntry();
//					Util util = new Util(ss); 
//					util.setValue("msg", "testaaaa");  
				}				
			}
		}		
	}
	
	int getNewMsgCount(long userid){
		return 90;
	}
	
	//setters and getters
	public SsionManager getSsionManager() {
		return ssionManager;
	}

	public void setSsionManager(SsionManager ssionManager) {
		this.ssionManager = ssionManager;
	}
}
